<html>
<head><meta charset="utf-8"><title>rc-terminology · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html">rc-terminology</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="175748967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175748967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175748967">(Sep 15 2019 at 13:26)</a>:</h4>
<p>For <code>ptr_eq</code> we could just say: "Returns true if the two pointers compare equal. "</p>



<a name="175748979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175748979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175748979">(Sep 15 2019 at 13:27)</a>:</h4>
<p>for, e.g., <code>strong_count()</code>, instead of:</p>



<a name="175748987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175748987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175748987">(Sep 15 2019 at 13:27)</a>:</h4>
<blockquote>
<p>Gets the number of strong (Rc) pointers to this value.</p>
</blockquote>
<p>maybe we can just say</p>
<blockquote>
<p>Gets the number of strong (Rc) pointers to this place.</p>
</blockquote>



<a name="175749054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175749054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175749054">(Sep 15 2019 at 13:29)</a>:</h4>
<p>We don't have a definition of object anywhere, so using "reference-counted object" without such a definition feels weird</p>



<a name="175749295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175749295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175749295">(Sep 15 2019 at 13:35)</a>:</h4>
<p>Also, is the Rc even required to point to a valid <code>T</code> ? (<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=1df78c20870b2791ecb7fd5bd7840d6d" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=1df78c20870b2791ecb7fd5bd7840d6d">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=1df78c20870b2791ecb7fd5bd7840d6d</a>) ?</p>



<a name="175799272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175799272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175799272">(Sep 16 2019 at 10:10)</a>:</h4>
<blockquote>
<p>We don't have a definition of object anywhere, so using "reference-counted object" without such a definition feels weird</p>
</blockquote>
<p>we could expand the <code>Rc</code> docs to explain this. we currently have</p>
<blockquote>
<p>The type Rc&lt;T&gt; provides shared ownership of a value of type T, allocated in the heap.</p>
</blockquote>
<p>so we could expand that and introduce any terminology we need.</p>



<a name="175801108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801108">(Sep 16 2019 at 10:47)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> one thing that confuses me is that "place" is currently defined as a "pointer"</p>



<a name="175801118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801118">(Sep 16 2019 at 10:47)</a>:</h4>
<p>I think that the word we are looking for here is "allocation"</p>



<a name="175801132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801132">(Sep 16 2019 at 10:47)</a>:</h4>
<p>A "place" is a pointer to a typed allocation, where the Rc stores the T is an "allocation", and what <code>ptr_eq</code> does is compare the addresses of the two allocations</p>



<a name="175801219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801219">(Sep 16 2019 at 10:49)</a>:</h4>
<p>Do we have a definition of allocation in the ucg reference ? maybe we could add one and relate them to place in the glossary</p>



<a name="175801235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801235">(Sep 16 2019 at 10:49)</a>:</h4>
<p>When people use object in the C++ object they mean a Rust value put in an allocation that's behind a place (giving the content of the allocation a type)</p>



<a name="175801239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801239">(Sep 16 2019 at 10:49)</a>:</h4>
<p>the allocation itself is untyped</p>



<a name="175801569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801569">(Sep 16 2019 at 10:55)</a>:</h4>
<blockquote>
<p>A "place" is a pointer to a typed allocation, where the Rc stores the T is an "allocation", and what <code>ptr_eq</code> does is compare the addresses of the two allocations</p>
</blockquote>
<p>a place can also point inside an allocation, i.e., only reference parts of it</p>



<a name="175801590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801590">(Sep 16 2019 at 10:55)</a>:</h4>
<p>also allocations are not typed in Rust. memory in general isn't. only values (and places) are.</p>



<a name="175801780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801780">(Sep 16 2019 at 10:58)</a>:</h4>
<p>Yes, which is why an Rc is similar to a Place, but it does not point to a place (it points to somewhere inside an allocation, it actually points to some offset after the start of an allocation, the ref count is stored before that offset in the same allocation)</p>



<a name="175801874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801874">(Sep 16 2019 at 10:59)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> so we might want to be more clear about what "points to an allocation" means</p>



<a name="175801925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801925">(Sep 16 2019 at 11:00)</a>:</h4>
<p>does it mean "points to the beginning of an allocation"?</p>



<a name="175801944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801944">(Sep 16 2019 at 11:00)</a>:</h4>
<p>"points to somewhere inside it" ?</p>



<a name="175801971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801971">(Sep 16 2019 at 11:01)</a>:</h4>
<p>I think that unless it is clarified, it can mean any of those, and therefore saying that the Rc points to an allocation containing a <code>T</code> is ok.</p>



<a name="175801983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175801983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175801983">(Sep 16 2019 at 11:01)</a>:</h4>
<p>It does not point to the beginning of such an allocation, but it does point to the beginning of a T within it</p>



<a name="175802451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175802451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175802451">(Sep 16 2019 at 11:09)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> so we might want to be more clear about what "points to an allocation" means</p>
</blockquote>
<p>I'd just not talk about "pointing to an allocation" in <code>Rc</code> docs</p>



<a name="175808424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175808424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175808424">(Sep 16 2019 at 12:50)</a>:</h4>
<p>What would you say?</p>



<a name="175809280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175809280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175809280">(Sep 16 2019 at 13:01)</a>:</h4>
<p>not sure, but not that^^</p>



<a name="175809338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175809338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175809338">(Sep 16 2019 at 13:02)</a>:</h4>
<p>or something where both interpretations are basically correct</p>



<a name="175809475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175809475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175809475">(Sep 16 2019 at 13:03)</a>:</h4>
<p>e.g. <code>ptr_eq</code> testing if both <code>Rc</code> "point to the same allocation" or so</p>



<a name="175823568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175823568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175823568">(Sep 16 2019 at 15:34)</a>:</h4>
<blockquote>
<p>I'd just not talk about "pointing to an allocation" in Rc docs<br>
e.g. ptr_eq testing if both Rc "point to the same allocation" or so</p>
</blockquote>
<p><span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="175823589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175823589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175823589">(Sep 16 2019 at 15:34)</a>:</h4>
<p>I'd be fine with that.</p>



<a name="175849684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology/near/175849684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/rc-terminology.html#175849684">(Sep 16 2019 at 20:31)</a>:</h4>
<p>"points to the same allocation" seems good, can't go wrong, I think</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>